﻿namespace principleawaitasync
{
    internal class Program
    {
        /// <summary>
        /// 异步编程4: async、await原理揭秘
        /// async的方法会被C#编译器编译成一个类，会主要根据await调用进行切分为多个状态，对async方法的调用会被拆分为对MoveNext的调用。用await看似是“等待”，经过编译后，其实没有“wait”。
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        static async Task Main(string[] args)
        {
            using (HttpClient httpClient = new HttpClient())
            {
                string html = await httpClient.GetStringAsync("https://www.baidu.com");
                await Console.Out.WriteLineAsync(html);
            }
            string filepath = @"d:\test\1.txt";
            string content = "写入内容";
            await File.WriteAllTextAsync(filepath, content);
            string filecontet = await File.ReadAllTextAsync(filepath);
            await Console.Out.WriteLineAsync(filecontet);
        }
    }
}